package com.mylibraryapplication.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mylibraryapplication.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * @author yinsujun  Created at 2016/7/26 14:14
 */
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
    private List<String> data=new ArrayList<>();
    private Context context;

    public MainAdapter(List<String> data,Context context) {
        this.data=data;
        this.context=context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.main_recycler_item,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(data.get(position));

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
//        @BindView(R.id.main_recycler_tv)
        TextView textView;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            textView= (TextView) itemView.findViewById(R.id.main_recycler_tv);
        }
    }
}
